// 1824 [动态规划区间覆盖] 完美答案收集 中
// http://oj.rnd.huawei.com/problems/1824/details
// mapRange.insert(make_pair(range.first, range.second));
// dp[i]将区间 [0,i) 覆盖所需的最少子区间的数量
// 输入 10
// 6
// 1 3
// 4 6
// 1 6
// 6 10
// 5 8
// 10 10
// 输出 2

#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;

//    ----
// --
//   ---
//        -----
//    -----
//  -----
int GetMinPeople(int questionsCount, int peopleCount,
                 const vector<pair<int, int>>& correctRanges) {
  const static int MAX_COUNT = 0x4fffffff;
  vector<int> dp(questionsCount + 1, MAX_COUNT);
  dp[0] = 0;
  for (int i = 1; i <= questionsCount; i++) {
    for (auto it : correctRanges) {
      if (it.first <= i && i <= it.second) {
        dp[i] = min(dp[i], dp[it.first - 1] + 1);
      }
    }
  }
  return dp[questionsCount] == MAX_COUNT ? -1 : dp[questionsCount];
}

int main() {
  int questionsCount = 10;
  cin >> questionsCount;
  int peopleCount = 6;
  cin >> peopleCount;

  vector<pair<int, int>> correctRanges(peopleCount);
  for (int i = 0; i < peopleCount; ++i) {
    cin >> correctRanges[i].first >> correctRanges[i].second;
  }
  cout << GetMinPeople(questionsCount, peopleCount, correctRanges);

  return 0;
}
